package com.jy.adscm.operation.hscrb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.hscrb.bean.FsCrushdetail;
import com.jy.adscm.operation.hscrb.mapper.mysql.FsCrushdetailMapper;
import com.jy.adscm.operation.hscrb.service.FsCrushdetailService;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-12-18
 */
@Service
public class FsCrushdetailServiceImpl extends ServiceImpl<FsCrushdetailMapper, FsCrushdetail> implements FsCrushdetailService {
   @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public Boolean updateFsCrushdetail(FsCrushdetail fsCrushdetail) {
        boolean result = super.updateById(fsCrushdetail);
        return result;
    }

    @Override
    public List<FsCrushdetail> selectByTid(String tid) {
        Wrapper<FsCrushdetail> wrapper =new EntityWrapper<>();
        wrapper.eq("TID",tid);
        List<FsCrushdetail> fsCrushdetails = super.selectList(wrapper);
        for (FsCrushdetail fsCrushdetail : fsCrushdetails) {
              if (AdscmBaseUtils.getInstance().isNotEmpty(fsCrushdetail.getNeeder(),null)){
                  JyUser jyUser = jyUserMapper.selectById(fsCrushdetail.getNeeder());
                  fsCrushdetail.setNeederName(jyUser.getName());
              }
              if (AdscmBaseUtils.getInstance().isNotEmpty(fsCrushdetail.getCustomer(),null)){
                  JyUser jyUser = jyUserMapper.selectById(fsCrushdetail.getCustomer());
                  fsCrushdetail.setCustomerName(jyUser.getName());
              }
        }
        return fsCrushdetails;
    }

    @Override
    public List<JyUser> selectUser() {
        Wrapper<JyUser> wrapper=new EntityWrapper<>();
        wrapper.setSqlSelect("id","name");
        List<JyUser> jyUsers = jyUserMapper.selectList(wrapper);
        return jyUsers;
    }
}
